package xdpm.nhom16.GUI;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class IconOverlay extends ItemizedOverlay<OverlayItem>{

	private ArrayList<OverlayItem> overlays = new ArrayList<OverlayItem>();
	
	private Context context;
	
	public IconOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
	}
	
	public IconOverlay(Drawable defaultMarker, Context context) {
		this(defaultMarker);
		this.context = context;
	}
	
	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return overlays.get(i);
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return overlays.size();
	}

	protected boolean onTap (int index) {
		OverlayItem item = overlays.get(index);
		AlertDialog.Builder dialog = new AlertDialog.Builder(context);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}
	
	public void addOverlay (OverlayItem overlay){
		overlays.add(overlay);
		this.populate();
	}
}



//Read more: http://www.javacodegeeks.com/2011/02/android-google-maps-tutorial.html